<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {margin: 0;overflow: hidden;}
    #canvas {background-color: antiquewhite;}
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.querySelector('#canvas');
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    const ctx = canvas.getContext('2d');

    const img = new Image();
    img.src = './images/dog.jpg';
    img.onload = function () {
      const { width, height } = img;
      /* 绘图+位移: drwaImage(image, x, y) */
      // ctx.drawImage(img, 50, 50);

      /* 绘图+位移+缩放: drwaImage(image, x, y, width, height) */
      // ctx.drawImage(img, 0, 0, width / 2, height / 2);
      
      /* 绘图+裁剪+位移+缩放: drwaImage(image, x1, y1, w1, h1, x2, y2, w2, h2) */
      ctx.drawImage(
        img,
        // 相机视口
        width/2, height/2, width/2, height/2,
        // 视图矩形
        0, 0, width, height
      );
    }

  </script>
</body>
</html>